package com.b2b2c.store.single.logic;

import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import javax.servlet.http.HttpServletRequest;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;

import com.b2b2c.store.single.entity.StoreAuthGroupAccess;
import com.b2b2c.store.single.mapper.StoreAuthGroupAccessMapper;
import com.b2b2c.store.single.service.IStoreGroupAccessService;


/**
 * 权限组
 * @author Administrator
 */
public class StoreAuthGroupAccessLogic extends AbstractLogic<StoreAuthGroupAccess, Object> implements IStoreGroupAccessService<StoreAuthGroupAccess>{
	
	

	public StoreAuthGroupAccessLogic(Map<String, String> args) {
		super(args);
		// TODO Auto-generated constructor stub
	}
	
	public StoreAuthGroupAccessLogic(HttpServletRequest req) {
		super(req);
		// TODO Auto-generated constructor stub
	}
	
	
	public List<StoreAuthGroupAccess> getAuthGroupByStore(RedisTemplate<String, List<StoreAuthGroupAccess>> redisTemplate)
	{
		
		ValueOperations<String, List<StoreAuthGroupAccess>> valueOption =  redisTemplate.opsForValue();
		
		
		String storeId = this.getReq().getSession().getAttribute("id").toString();
		
		String key = "auth-access"+ storeId;
		List<StoreAuthGroupAccess> data = valueOption.get(key);
		
		if (data != null) {
			return data;
		}
		
		short id = Short.valueOf(storeId);
		
		data = this.getSqlTemp().getMapper(StoreAuthGroupAccessMapper.class).getAuthGroupAccessByStore(id);
		
		valueOption.set(key, data, 60, TimeUnit.SECONDS);
		
		return data;
	}
	
	
	
	/**
	 * 
	 */
	public Map<String, Map<String, String>> getValidateRule() {
		// TODO Auto-generated method stub
		
		
		return null;
	}


}
